package com.bocai.dahuatech.ui.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.dahuatech.Bean.BaseBean;
import com.bocai.dahuatech.Bean.ProductSeriesListBean;
import com.bocai.dahuatech.R;
import com.bocai.dahuatech.base.BaseActivity;
import com.bocai.dahuatech.utils.AESUtils;
import com.google.gson.Gson;

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 产品1级
 */
public class ProductActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.ll_product_01)
    LinearLayout llProduct01;
    @Bind(R.id.tv_product_01)
    TextView tvProduct01;
    @Bind(R.id.ll_product_02)
    LinearLayout llProduct02;
    @Bind(R.id.tv_product_02)
    TextView tvProduct02;
    @Bind(R.id.ll_product_03)
    LinearLayout llProduct03;
    @Bind(R.id.tv_product_03)
    TextView tvProduct03;
    @Bind(R.id.ll_product_04)
    LinearLayout llProduct04;
    @Bind(R.id.tv_product_04)
    TextView tvProduct04;
    @Bind(R.id.ll_product_05)
    LinearLayout llProduct05;
    @Bind(R.id.tv_product_05)
    TextView tvProduct05;
    @Bind(R.id.ll_product_06)
    LinearLayout llProduct06;
    @Bind(R.id.tv_product_06)
    TextView tvProduct06;
    @Bind(R.id.ll_product_07)
    LinearLayout llProduct07;
    @Bind(R.id.tv_product_07)
    TextView tvProduct07;
    @Bind(R.id.ll_product_08)
    LinearLayout llProduct08;
    @Bind(R.id.tv_product_08)
    TextView tvProduct08;
    @Bind(R.id.ll_product_09)
    LinearLayout llProduct09;
    @Bind(R.id.tv_product_09)
    TextView tvProduct09;
    @Bind(R.id.ll_product_10)
    LinearLayout llProduct10;
    @Bind(R.id.tv_product_10)
    TextView tvProduct10;
    ProductSeriesListBean bean;
    @Override
    protected int contentView() {
        return R.layout.activity_product;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        initToolbar(R.string.product);
        initEvent();
        getDatas();
    }
    private void getDatas() {
        getTestApi().getProductSeriesList(1,0)
                .compose(this.<BaseBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
    Observer<BaseBean> observer=new Observer<BaseBean>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {
            hideLoading();
            showToast(R.string.neterror);
            Log.e("error", e.toString());
        }

        @Override
        public void onNext(BaseBean baseBean) {
            if (baseBean.getReturnNo().equals("1"))
            {
                String result= AESUtils.decode(baseBean.getContent());
                result=start+result+end;
                Log.e("result",result);

                bean=new Gson().fromJson(result,ProductSeriesListBean.class);
//                mListView.setAdapter(new ProductSecendAdapter(ProductSecendActivity.this,bean.getContent()));
            }else
            {
                showToast(baseBean.getReturnInfo());
            }
        }
    };
    @Override
    protected void initEvent() {
        llProduct01.setOnClickListener(this);
        llProduct02.setOnClickListener(this);
        llProduct03.setOnClickListener(this);
        llProduct04.setOnClickListener(this);
        llProduct05.setOnClickListener(this);
        llProduct06.setOnClickListener(this);
        llProduct07.setOnClickListener(this);
        llProduct08.setOnClickListener(this);
        llProduct09.setOnClickListener(this);
        llProduct10.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        Intent intent=new Intent(this,ProductSecendActivity.class);
        switch (v.getId())
        {
            case R.id.ll_product_01:
                intent.putExtra("text",tvProduct01.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_02:
                intent.putExtra("text",tvProduct02.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_03:
                intent.putExtra("text",tvProduct03.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_04:
                intent.putExtra("text",tvProduct04.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_05:
                intent.putExtra("text",tvProduct05.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_06:
                intent.putExtra("text",tvProduct06.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_07:
                intent.putExtra("text",tvProduct07.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_08:
                intent.putExtra("text",tvProduct08.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_09:
                intent.putExtra("text",tvProduct09.getText().toString());
                startActivity(intent);
                break;
            case R.id.ll_product_10:
                intent.putExtra("text",tvProduct10.getText().toString());
                startActivity(intent);
                break;
        }
    }
}
